<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<!--_meta 作为公共模版分离出去-->
<!DOCTYPE HTML>
<html>
<head>
    <meta charset="utf-8">
    <meta name="renderer" content="webkit|ie-comp|ie-stand">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport"
          content="width=device-width,initial-scale=1,minimum-scale=1.0,maximum-scale=1.0,user-scalable=no"/>
    <meta http-equiv="Cache-Control" content="no-siteapp"/>
    <link rel="Bookmark" href="/icon/favicon.ico">
    <link rel="Shortcut Icon" href="/icon/favicon.ico"/>
    <!--[if lt IE 9]>
    <script type="text/javascript" src="lib/html5shiv.js"></script>
    <script type="text/javascript" src="lib/respond.min.js"></script>
    <![endif]-->
    <link rel="stylesheet" type="text/css" href="static/h-ui/css/H-ui.min.css"/>
    <link rel="stylesheet" type="text/css" href="static/h-ui.admin/css/H-ui.admin.css"/>
    <link rel="stylesheet" type="text/css" href="lib/Hui-iconfont/1.0.8/iconfont.css"/>
    <link rel="stylesheet" type="text/css" href="static/h-ui.admin/skin/default/skin.css" id="skin"/>
    <link rel="stylesheet" type="text/css" href="static/h-ui.admin/css/style.css"/>

    <![endif]-->
    <!--/meta 作为公共模版分离出去-->

    <title>添加用户</title>
</head>
<body>


<article class="page-container">
    <form class="form form-horizontal" id="form-order-edit">
        <div class="row cl" id="order-content">
            <label class="form-label col-xs-4 col-sm-3"><span class="c-red"></span>订单内容：</label>
            <div class="formControls col-xs-8 col-sm-9">
                <div id="order-content-dom"></div>
            </div>
        </div>
        <input type="text" hidden value="" placeholder="" id="wxOrderId" name="wxOrderId" >

        <div class="row cl">
            <label class="form-label col-xs-4 col-sm-3"><span class="c-red">*</span>收货人：</label>
            <div class="formControls col-xs-8 col-sm-9">
                <input type="text" class="input-text" value="" placeholder="" id="receiverName" name="receiverName">
            </div>
        </div>
        <div class="row cl">
            <label class="form-label col-xs-4 col-sm-3">联系电话：</label>
            <div class="formControls col-xs-8 col-sm-9">
                <input type="text" class="input-text" autocomplete="off" placeholder="" id="receiverPhone"
                       name="receiverPhone">
            </div>
        </div>
        <div class="row cl">
            <label class="form-label col-xs-4 col-sm-3"><span class="c-red">*</span>地址类型：</label>
            <div class="formControls col-xs-8 col-sm-9">
                <div class="skin-minimal">
                    <div class="radio-box">
                        <input value="1" type="radio" id="radio-1" name="addressType">
                        <label for="radio-1">医院地址</label>
                    </div>
                    <div class="radio-box">
                        <input value="2" type="radio" id="radio-2" name="addressType">
                        <label for="radio-2">其他地址</label>
                    </div>
                </div>
            </div>
        </div>
        <div class="row cl" id="hospital">
            <label class="form-label col-xs-4 col-sm-3"><span class="c-red">*</span>医院名称：</label>
            <div class="formControls col-xs-8 col-sm-9">
                <input type="text" onclick="chooseHospital()" readonly  class="input-text" autocomplete="off" value="" placeholder="" id="hospitalAddress" name="hospitalAddress">
            </div>
        </div>
        <div class="row cl" id="prov" style="display: none;">
            <label class="form-label col-xs-4 col-sm-3"><span class="c-red">*</span>省市区：</label>
            <div class="formControls col-xs-8 col-sm-9" data-toggle="distpicker" id="distpicker">
                <select id="province" name="receiverState"></select>
                <select id="city" name="receiverCity"></select>
                <select id="district" name="receiverDistrict"></select>
                <input type="text" style="margin-top: 10px" id="otherAddress" class="input-text" autocomplete="off" value="" placeholder="村/街道/小区">
            </div>
        </div>
        <div class="row cl">
            <label class="form-label col-xs-4 col-sm-3"><span class="c-red">*</span>详细地址：</label>
            <div class="formControls col-xs-8 col-sm-9">
                <input type="text" class="input-text" hidden autocomplete="off" value="" placeholder="" id="receiverAddress"
                       name="receiverAddress">
                <input type="text" class="input-text" autocomplete="off" value="" placeholder="" id="address"
                       name="address">
            </div>
        </div>
        <div class="row cl">
            <label class="form-label col-xs-4 col-sm-3"><span class="c-red">*</span>预约时间：</label>
            <div class="formControls col-xs-6 col-sm-5">
                <input type="text" onfocus="WdatePicker({ minDate:'%y-%M-%d',dateFmt:'yyyy-MM-dd HH:mm:ss'})"
                       name="reserveTime" class="input-text Wdate" style="width:180px;" readonly="true">
            </div>
        </div>


        <div class="row cl">
            <label class="form-label col-xs-4 col-sm-3"><span class="c-red"></span>支付方式：</label>
            <div class="formControls col-xs-8 col-sm-9">
                <span class="select-box">
                    <select class="select" name="paymentType" id="paymentType">
                    <option value="待定">待定</option>
                    <option value="现金">现金</option>
                    <option value="刷卡">刷卡</option>
                    <option value="微信">微信</option>
                    <option value="支付宝">支付宝</option>
                    </select>
                </span>
            </div>
        </div>

        <div class="row cl">
            <label class="form-label col-xs-4 col-sm-3"><span class="c-red"></span>医保类型：</label>
            <div class="formControls col-xs-8 col-sm-9">
                <span class="select-box">
                    <select class="select" name="insuranceType" id="insuranceType">
                        <option value="" selected="selected" disabled="disabled" style="display: none"></option>
                        <option value="城职">城职</option>
                                                <option value="铁路医保">铁路医保</option>
                        <option value="省医保">省医保</option>

                        <option value="城居/农合">城居/农合</option>
                        <option value="其他">其他</option>
                    </select>
                </span>
            </div>
        </div>

        <div class="row cl">
            <label class="form-label col-xs-4 col-sm-3"><span class="c-red"></span>医保地址：</label>
            <div class="formControls col-xs-8 col-sm-9">
                <span class="select-box">
                    <select class="select" name="insurance" id="insurance">
                    <option value="" selected="selected" disabled="disabled" style="display: none"></option>
                    <option value="长沙">长沙</option>
                    <option value="株洲">株洲</option>
                    <option value="湘潭">湘潭</option>
                    <option value="益阳">益阳</option>
                    <option value="常德">常德</option>
                    <option value="岳阳">岳阳</option>
                    <option value="娄底">娄底</option>
                    <option value="邵阳">邵阳</option>
                    <option value="怀化">怀化</option>
                    <option value="湘西">湘西</option>
                    <option value="湘西">郴州</option>
                    <option value="湘西">张家界</option>
                    <option value="湘西">衡阳</option>
                    <option value="湘西">永州</option>
                    <option value="湘西">省外</option>
                    <option value="湘西">无医保</option>
                    </select>
                </span>
            </div>
        </div>

        <div class="row cl">
            <label class="form-label col-xs-4 col-sm-3"><span class="c-red">*</span>选择药品：</label>
            <div class="formControls col-xs-8 col-sm-9" id="list" >
                <input type="text" hidden value="" placeholder="" id="medicineId" name="medicineId" >
                <input type="text" onclick="chooseMedicine()" readonly  class="input-text" autocomplete="off" value="" placeholder="" id="medicine" >
            </div>
        </div>
        <div class="row cl">
            <label class="form-label col-xs-4 col-sm-3"><span class="c-red">*</span>药品数量：</label>
            <div class="formControls col-xs-8 col-sm-9" >
                <input type="number"  class="input-text"  value="1"  id="num" name="num" >
            </div>
        </div>
        <div class="row cl">
            <label class="form-label col-xs-4 col-sm-3"><span class="c-red"></span>是否冷链：</label>
            <div class="formControls col-xs-8 col-sm-9">
                <span class="select-box">
                    <select class="select" name="freezing" id="freezing">
                    <option value="0">否</option>
                                            <option value="1">是</option>
                    </select>
                </span>
            </div>
        </div>
        <div class="row cl">
            <label class="form-label col-xs-4 col-sm-3">备注：</label>
            <div class="formControls col-xs-8 col-sm-9">
                <textarea  class="textarea" id="prescriptionPic" name="prescriptionPic" placeholder="" ></textarea>
            </div>
        </div>

        <div class="row cl">
            <label class="form-label col-xs-4 col-sm-3"><span class="c-red"></span>下单人：</label>
            <div class="formControls col-xs-8 col-sm-9" >
                <input type="text" hidden value="125" placeholder="" id="memberId" name="memberId" >
                <input type="text" onclick="chooseMember()" readonly  class="input-text" autocomplete="off" value="" placeholder="不填默认为药店" id="memberName" >
            </div>
        </div>

        <div class="row cl">
            <div class="col-xs-8 col-sm-9 col-xs-offset-4 col-sm-offset-3">
                <input id="saveButton" class="btn btn-primary radius" type="submit" value="&nbsp;&nbsp;提交&nbsp;&nbsp;">
            </div>
        </div>
    </form>
</article>

<!--_footer 作为公共模版分离出去-->
<script type="text/javascript" src="lib/jquery/1.9.1/jquery.min.js"></script>
<script type="text/javascript" src="lib/layer/2.4/layer.js"></script>
<script type="text/javascript" src="static/h-ui/js/H-ui.min.js"></script>
<script type="text/javascript" src="static/h-ui.admin/js/H-ui.admin.js"></script> <!--/_footer 作为公共模版分离出去-->

<!--请在下方写此页面业务相关的脚本-->
<script type="text/javascript" src="lib/My97DatePicker/4.8/WdatePicker.js"></script>
<script type="text/javascript" src="lib/jquery.validation/1.14.0/jquery.validate.js"></script>
<script type="text/javascript" src="lib/jquery.validation/1.14.0/validate-methods.js"></script>
<script type="text/javascript" src="lib/jquery.validation/1.14.0/messages_zh.js"></script>
<script type="text/javascript" src="lib/province/distpicker.data.js"></script>
<script type="text/javascript" src="lib/province/distpicker.js"></script>
<script type="text/javascript" src="lib/addressParse/arealist.js"></script>
<script type="text/javascript" src="lib/addressParse/address-parse.js"></script>
<script type="text/javascript">


    var addressType = 1
    function radioCheck(){
        $('.skin-minimal input').iCheck({
            radioClass: 'iradio-blue',
            increaseArea: '20%'
        })
        $('#radio-1').iCheck('check')

        $("input:radio[name='addressType']").on('ifChecked', function (event) {
            var value = $(this).val()
            addressType = value
            if (value == "1") {
                $("#hospital").show()
                $("#prov").hide()
            } else if (value == "2") {
                $("#prov").show()
                $("#hospital").hide()
            }
        });
    }
    radioCheck()

    var result = parent.result

    if (result && result !=null){
        $('#distpicker').distpicker({
            province: result.province ? (result.province +"省"):"湖南省",
            city: result.city ? (result.city +"市"): "",
            district:  result.area ? result.area : "",
        });
        $('#radio-2').iCheck('check')
        if (result.mobile && result.mobile !==""){
            $("#receiverPhone").val(result.mobile)
        }
        if (result.name && result.name !==""){
            $("#receiverName").val(result.name)
        }
        if (result.addr && result.addr !==""){
            $("#receiverAddress").val(result.addr)
            $("#address").val(result.addr)
        }

    } else{
        $('#distpicker').distpicker({
            province: '湖南省',
            city: '长沙市',
            district: '芙蓉区'
        });
    }

    var orderContent = parent.orderContent
    if ( !orderContent || orderContent == ""){
        $("#order-content").hide()
    }else{
        $("#order-content-dom").html(orderContent)
    }
    var memberId = parent.memberId
    var memberName = parent.memberName
    if (!memberId || memberId == ""){
    }else{
        $("#memberId").attr("value", memberId);
        $("#memberName").attr("value", memberName);
        $("#memberName").attr("disabled", "disabled");
    }

    var wxOrderId = parent.wxOrderId
    if (wxOrderId && wxOrderId!=""){
        $("#wxOrderId").attr("value", wxOrderId);
    }

    $("#form-order-edit").validate({
        rules: {
            receiverName: {
                required: true,
                minlength: 2
            },
            reserveTime: {
                required: true
            }
        },
        onkeyup: false,
        focusCleanup: false,
        success: "valid",
        submitHandler: function (form) {
            var index = layer.load(3);
            if (addressType == "1"){
                $("#receiverAddress").val( $("#hospitalAddress").val() +"|"+$("#address").val())
            } else {
                $("#receiverAddress").val( $("#otherAddress").val() +"|"+$("#address").val())
            }
            $(form).ajaxSubmit({
                url:"./order/add",
                method:"post",
                success: function (data) {
                    layer.closeAll()
                    if (data.success == true) {
                        if (parent.location.pathname != '/') {
                            if (!result){
                                parent.refresh();
                            }
                            parent.msgSuccess("添加成功!");
                            var index = parent.layer.getFrameIndex(window.name);
                            parent.layer.close(index);
                        } else {
                            layer.confirm('添加成功!', {
                                btn: ['确认'], icon: 1
                            }, function () {
                                var index = parent.layer.getFrameIndex(window.name);
                                parent.layer.close(index);
                            });
                        }
                    } else {
                        layer.alert('添加失败! ' + data.message, {title: '错误信息', icon: 2});
                    }
                },
                error: function (XMLHttpRequest) {
                    ayer.closeAll()
                    layer.alert('数据处理失败! 错误码:' + XMLHttpRequest.status + ' 错误信息:' + JSON.parse(XMLHttpRequest.responseText).message, {
                        title: '错误信息',
                        icon: 2
                    });
                }
            });
        }
    });

    function chooseHospital() {
        layer_show("选择医院", "choose-hospital");
    }

    function setTidAndTname (id,name,freezing) {
        $("#medicine").val(name)
        $("#medicineId").val(id)
        $("#freezing").val(freezing)
    }
    function setHospital(hospital) {
        $('#distpicker').distpicker('destroy');
        $('#distpicker').distpicker({
            province: hospital.hospitalProvince || "湖南省",
            city: hospital.hospitalCity,
            district:  hospital.hospitalDis
        });
        $('#hospitalAddress').val(hospital.hospitalName)
    }
    var role = 1

    function fenpei(id,name) {
        $("#memberId").val(id)
        $("#memberName").val(name)

    }

    function chooseMember() {
        layer_show("选择下单人", "choose-member");
    }
    function chooseMedicine() {
        layer_show("选择药品", "choose-medicine");
    }

    function addrParse(){


      var lIndex =  layer.open({
            type: 1,
            title:"智能粘贴",
            area:["300px","260px"],
            btn:['提交'],
            btn1:function(){
                var addr = $('#addrText').val()
                if (addr && addr !==""){
                    var result =  parse(addr)

                    $('#distpicker').distpicker('destroy');
                    $('#distpicker').distpicker({
                        province: result.province ? (result.province +"省"):"湖南省",
                        city: result.city ? (result.city +"市"): "",
                        district:  result.area ? result.area : "",
                    });
                    layer.close(lIndex)
                    $('#radio-2').iCheck('check')
                    if (result.mobile && result.mobile !==""){
                        $("#receiverPhone").val(result.mobile)
                    }
                    if (result.name && result.name !==""){
                        $("#receiverName").val(result.name)
                    }
                    if (result.addr && result.addr !==""){
                        $("#receiverAddress").val(result.addr)
                        $("#address").val(result.addr)
                    }
                }
            },
            content: '<div class="formControls col-xs-8 col-sm-9" style="margin-top:20px "> <textarea id="addrText" name="description" cols="" rows="" class="textarea" placeholder="地址粘贴到这" dragonfly="true"></textarea></div>' //这里content是一个普通的String
        });
    }
    parseArea(areaList);
</script>
<!--/请在上方写此页面业务相关的脚本-->
</body>
</html>